// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso.objects;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import se.krka.kahlua.vm.KahluaTable;
import zombie.Lua.LuaEventManager;
import zombie.core.Core;
import zombie.core.Rand;
import zombie.core.opengl.Shader;
import zombie.core.textures.ColorInfo;
import zombie.core.textures.Texture;
import zombie.iso.IsoCell;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoHeatSource;
import zombie.iso.IsoLightSource;
import zombie.iso.IsoMovingObject;
import zombie.iso.IsoObject;
import zombie.iso.IsoWorld;
import zombie.iso.SpriteDetails.IsoFlagType;
import zombie.iso.areas.SafeHouse;
import zombie.iso.sprite.IsoDirectionFrame;
import zombie.iso.sprite.IsoSprite;
import zombie.iso.sprite.IsoSpriteInstance;
import zombie.network.GameClient;
import zombie.network.GameServer;
import zombie.network.ServerOptions;
import zombie.ui.TutorialManager;

public class IsoFire extends IsoObject {
    public int Age = 0;
    public int Energy = 0;
    public int Life;
    public int LifeStage;
    public int LifeStageDuration;
    public int LifeStageTimer;
    public int MaxLife = 3000;
    public int MinLife = 800;
    public int SpreadDelay;
    public int SpreadTimer;
    public int numFlameParticles;
    public boolean perm = false;
    public boolean bSmoke = false;
    public IsoLightSource LightSource = null;
    public int LightRadius = 1;
    public float LightOscillator = 0.0F;
    private IsoHeatSource heatSource;
    private float accum = 0.0F;

    public IsoFire(IsoCell cell) {
        super(cell);
    }

    public IsoFire(IsoCell cell, IsoGridSquare gridSquare) {
        super(cell);
        this.square = gridSquare;
        this.perm = true;
    }

    @Override
    public String getObjectName() {
        return "Fire";
    }

    @Override
    public void save(ByteBuffer output, boolean IS_DEBUG_SAVE) throws IOException {
        ArrayList arrayList = this.AttachedAnimSprite;
        this.AttachedAnimSprite = null;
        super.save(output, IS_DEBUG_SAVE);
        this.AttachedAnimSprite = arrayList;
        this.sprite = null;
        output.putInt(this.Life);
        output.putInt(this.SpreadDelay);
        output.putInt(this.LifeStage - 1);
        output.putInt(this.LifeStageTimer);
        output.putInt(this.LifeStageDuration);
        output.putInt(this.Energy);
        output.putInt(this.numFlameParticles);
        output.putInt(this.SpreadTimer);
        output.putInt(this.Age);
        output.put((byte)(this.perm ? 1 : 0));
        output.put((byte)this.LightRadius);
        output.put((byte)(this.bSmoke ? 1 : 0));
    }

    @Override
    public void load(ByteBuffer b, int WorldVersion, boolean IS_DEBUG_SAVE) throws IOException {
        super.load(b, WorldVersion, IS_DEBUG_SAVE);
        this.sprite = null;
        this.Life = b.getInt();
        this.SpreadDelay = b.getInt();
        this.LifeStage = b.getInt();
        this.LifeStageTimer = b.getInt();
        this.LifeStageDuration = b.getInt();
        this.Energy = b.getInt();
        this.numFlameParticles = b.getInt();
        this.SpreadTimer = b.getInt();
        this.Age = b.getInt();
        this.perm = b.get() == 1;
        this.LightRadius = b.get() & 255;
        if (WorldVersion >= 89) {
            this.bSmoke = b.get() == 1;
        }

        if (this.perm) {
            this.AttachAnim("Fire", "01", 4, IsoFireManager.FireAnimDelay, -16, -78, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
        } else {
            if (this.numFlameParticles == 0) {
                this.numFlameParticles = 1;
            }

            switch (this.LifeStage) {
                case -1:
                    this.LifeStage = 0;

                    for (int _int = 0; _int < this.numFlameParticles; _int++) {
                        this.AttachAnim(
                            "Fire",
                            "01",
                            4,
                            IsoFireManager.FireAnimDelay,
                            -16 + -16 + Rand.Next(32),
                            -85 + -16 + Rand.Next(32),
                            true,
                            0,
                            false,
                            0.7F,
                            IsoFireManager.FireTintMod
                        );
                    }
                    break;
                case 0:
                    this.LifeStage = 1;
                    this.LifeStageTimer = this.LifeStageDuration;
                    this.AttachAnim("Fire", "02", 4, IsoFireManager.FireAnimDelay, -16, -72, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                    break;
                case 1:
                    this.LifeStage = 2;
                    this.LifeStageTimer = this.LifeStageDuration;
                    this.AttachAnim("Smoke", "01", 4, IsoFireManager.SmokeAnimDelay, -9, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                    this.AttachAnim("Fire", "03", 4, IsoFireManager.FireAnimDelay, -9, -52, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                    break;
                case 2:
                    this.LifeStage = 3;
                    this.LifeStageTimer = this.LifeStageDuration / 3;
                    this.RemoveAttachedAnims();
                    this.AttachAnim("Smoke", "02", 4, IsoFireManager.SmokeAnimDelay, 0, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                    this.AttachAnim("Fire", "02", 4, IsoFireManager.FireAnimDelay, -16, -72, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                    break;
                case 3:
                    this.LifeStage = 4;
                    this.LifeStageTimer = this.LifeStageDuration / 3;
                    this.RemoveAttachedAnims();
                    if (this.bSmoke) {
                        this.AttachAnim("Smoke", "03", 4, IsoFireManager.SmokeAnimDelay, 0, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                    } else {
                        this.AttachAnim("Smoke", "03", 4, IsoFireManager.SmokeAnimDelay, 0, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                        this.AttachAnim("Fire", "01", 4, IsoFireManager.FireAnimDelay, -16, -85, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                    }
                    break;
                case 4:
                    this.LifeStage = 5;
                    this.LifeStageTimer = this.LifeStageDuration / 3;
                    this.RemoveAttachedAnims();
                    this.AttachAnim("Smoke", "01", 4, IsoFireManager.SmokeAnimDelay, -9, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
            }

            if (this.square != null) {
                if (this.LifeStage < 4) {
                    this.square.getProperties().Set(IsoFlagType.burning);
                } else {
                    this.square.getProperties().Set(IsoFlagType.smoke);
                }
            }
        }
    }

    public IsoFire(IsoCell cell, IsoGridSquare gridSquare, boolean CanBurnAnywhere, int StartingEnergy, int SetLife, boolean isSmoke) {
        this.square = gridSquare;
        this.DirtySlice();
        this.square.getProperties().Set(IsoFlagType.smoke);
        this.AttachAnim("Smoke", "03", 4, IsoFireManager.SmokeAnimDelay, 0, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
        this.Life = this.MinLife + Rand.Next(this.MaxLife - this.MinLife);
        if (SetLife > 0) {
            this.Life = SetLife;
        }

        this.LifeStage = 4;
        this.LifeStageTimer = this.LifeStageDuration = this.Life / 4;
        this.Energy = StartingEnergy;
        this.bSmoke = isSmoke;
    }

    public IsoFire(IsoCell cell, IsoGridSquare gridSquare, boolean CanBurnAnywhere, int StartingEnergy, int SetLife) {
        this.square = gridSquare;
        this.DirtySlice();
        this.numFlameParticles = 2 + Rand.Next(2);

        for (int _int = 0; _int < this.numFlameParticles; _int++) {
            this.AttachAnim(
                "Fire",
                "01",
                4,
                IsoFireManager.FireAnimDelay,
                -16 + -16 + Rand.Next(32),
                -85 + -16 + Rand.Next(32),
                true,
                0,
                false,
                0.7F,
                IsoFireManager.FireTintMod
            );
        }

        this.Life = this.MinLife + Rand.Next(this.MaxLife - this.MinLife);
        if (SetLife > 0) {
            this.Life = SetLife;
        }

        if (this.square.getProperties() != null && !this.square.getProperties().Is(IsoFlagType.vegitation) && this.square.getFloor() != null) {
            this.Life = this.Life - this.square.getFloor().getSprite().firerequirement * 100;
            if (this.Life < 600) {
                this.Life = Rand.Next(300, 600);
            }
        }

        this.SpreadDelay = this.SpreadTimer = Rand.Next(this.Life - this.Life / 2);
        this.LifeStage = 0;
        this.LifeStageTimer = this.LifeStageDuration = this.Life / 4;
        if (TutorialManager.instance.Active) {
            this.LifeStageDuration *= 2;
            this.Life *= 2;
        }

        if (TutorialManager.instance.Active) {
            this.SpreadDelay = this.SpreadTimer /= 4;
        }

        gridSquare.getProperties().Set(IsoFlagType.burning);
        this.Energy = StartingEnergy;
        if (this.square.getProperties().Is(IsoFlagType.vegitation)) {
            this.Energy += 50;
        }

        LuaEventManager.triggerEvent("OnNewFire", this);
    }

    public IsoFire(IsoCell cell, IsoGridSquare gridSquare, boolean CanBurnAnywhere, int StartingEnergy) {
        this(cell, gridSquare, CanBurnAnywhere, StartingEnergy, 0);
    }

    public static boolean CanAddSmoke(IsoGridSquare gridSquare, boolean CanBurnAnywhere) {
        return CanAddFire(gridSquare, CanBurnAnywhere, true);
    }

    public static boolean CanAddFire(IsoGridSquare gridSquare, boolean CanBurnAnywhere) {
        return CanAddFire(gridSquare, CanBurnAnywhere, false);
    }

    public static boolean CanAddFire(IsoGridSquare gridSquare, boolean CanBurnAnywhere, boolean smoke) {
        if (!smoke && (GameServer.bServer || GameClient.bClient) && ServerOptions.instance.NoFire.getValue()) {
            return false;
        } else if (gridSquare == null || gridSquare.getObjects().isEmpty()) {
            return false;
        } else if (gridSquare.Is(IsoFlagType.water)) {
            return false;
        } else if (!CanBurnAnywhere && gridSquare.getProperties().Is(IsoFlagType.burntOut)) {
            return false;
        } else if (gridSquare.getProperties().Is(IsoFlagType.burning) || gridSquare.getProperties().Is(IsoFlagType.smoke)) {
            return false;
        } else {
            return !CanBurnAnywhere && !Fire_IsSquareFlamable(gridSquare)
                ? false
                : smoke
                    || !GameServer.bServer && !GameClient.bClient
                    || SafeHouse.getSafeHouse(gridSquare) == null
                    || ServerOptions.instance.SafehouseAllowFire.getValue();
        }
    }

    public static boolean Fire_IsSquareFlamable(IsoGridSquare gridSquare) {
        return !gridSquare.getProperties().Is(IsoFlagType.unflamable);
    }

    @Override
    public boolean HasTooltip() {
        return false;
    }

    public void Spread() {
        if (!GameClient.bClient) {
            if (zombie.SandboxOptions.instance.FireSpread.getValue()) {
                if (this.getCell() != null) {
                    if (this.square != null) {
                        if (this.LifeStage < 4) {
                            IsoGridSquare isoGridSquare = null;
                            int int0 = Rand.Next(3) + 1;
                            if (Rand.Next(50) == 0) {
                                int0 += 15;
                            }

                            if (TutorialManager.instance.Active) {
                                int0 += 15;
                            }

                            for (int int1 = 0; int1 < int0; int1++) {
                                int int2 = Rand.Next(13);
                                switch (int2) {
                                    case 0:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX(), this.square.getY() - 1, this.square.getZ());
                                        break;
                                    case 1:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX() + 1, this.square.getY() - 1, this.square.getZ());
                                        break;
                                    case 2:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX() + 1, this.square.getY(), this.square.getZ());
                                        break;
                                    case 3:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX() + 1, this.square.getY() + 1, this.square.getZ());
                                        break;
                                    case 4:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX(), this.square.getY() + 1, this.square.getZ());
                                        break;
                                    case 5:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX() - 1, this.square.getY() + 1, this.square.getZ());
                                        break;
                                    case 6:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX() - 1, this.square.getY(), this.square.getZ());
                                        break;
                                    case 7:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX() - 1, this.square.getY() - 1, this.square.getZ());
                                        break;
                                    case 8:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX() - 1, this.square.getY() - 1, this.square.getZ() - 1);
                                        break;
                                    case 9:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX() - 1, this.square.getY(), this.square.getZ() - 1);
                                        break;
                                    case 10:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX(), this.square.getY() - 1, this.square.getZ() - 1);
                                        break;
                                    case 11:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX(), this.square.getY(), this.square.getZ() - 1);
                                        break;
                                    case 12:
                                        isoGridSquare = this.getCell().getGridSquare(this.square.getX(), this.square.getY(), this.square.getZ() + 1);
                                }

                                if (CanAddFire(isoGridSquare, false)) {
                                    int int3 = this.getSquaresEnergyRequirement(isoGridSquare);
                                    if (this.Energy >= int3) {
                                        this.Energy -= int3;
                                        if (GameServer.bServer) {
                                            this.sendObjectChange("Energy");
                                        }

                                        if (RainManager.isRaining()) {
                                            return;
                                        }

                                        int int4 = isoGridSquare.getProperties().Is(IsoFlagType.exterior) ? this.Energy : int3 * 2;
                                        IsoFireManager.StartFire(this.getCell(), isoGridSquare, false, int4);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public boolean TestCollide(IsoMovingObject obj, IsoGridSquare PassedObjectSquare) {
        return this.square == PassedObjectSquare;
    }

    @Override
    public IsoObject.VisionResult TestVision(IsoGridSquare from, IsoGridSquare to) {
        return IsoObject.VisionResult.NoEffect;
    }

    @Override
    public void update() {
        if (this.getObjectIndex() != -1) {
            if (!GameServer.bServer) {
                IsoFireManager.updateSound(this);
            }

            if (this.LifeStage < 4) {
                this.square.getProperties().Set(IsoFlagType.burning);
            } else {
                this.square.getProperties().Set(IsoFlagType.smoke);
            }

            if (!this.bSmoke && this.LifeStage < 5) {
                this.square.BurnTick();
            }

            int int0 = this.AttachedAnimSprite.size();

            for (int int1 = 0; int1 < int0; int1++) {
                IsoSpriteInstance isoSpriteInstance = (IsoSpriteInstance)this.AttachedAnimSprite.get(int1);
                IsoSprite isoSprite = isoSpriteInstance.parentSprite;
                isoSpriteInstance.update();
                float _float = zombie.GameTime.instance.getMultipliedSecondsSinceLastUpdate() * 60.0F;
                isoSpriteInstance.Frame = isoSpriteInstance.Frame + isoSpriteInstance.AnimFrameIncrease * _float;
                if ((int)isoSpriteInstance.Frame >= isoSprite.CurrentAnim.Frames.size() && isoSprite.Loop && isoSpriteInstance.Looped) {
                    isoSpriteInstance.Frame = 0.0F;
                }
            }

            if (!this.bSmoke && !GameServer.bServer && this.LightSource == null) {
                this.LightSource = new IsoLightSource(
                    this.square.getX(), this.square.getY(), this.square.getZ(), 0.61F, 0.165F, 0.0F, this.perm ? this.LightRadius : 5
                );
                IsoWorld.instance.CurrentCell.addLamppost(this.LightSource);
            }

            if (this.perm) {
                if (this.heatSource == null) {
                    this.heatSource = new IsoHeatSource(this.square.x, this.square.y, this.square.z, this.LightRadius, 35);
                    IsoWorld.instance.CurrentCell.addHeatSource(this.heatSource);
                } else {
                    this.heatSource.setRadius(this.LightRadius);
                }
            } else {
                this.accum = this.accum + zombie.GameTime.getInstance().getMultiplier() / 1.6F;

                while (this.accum > 1.0F) {
                    this.accum--;
                    this.Age++;
                    if (this.LifeStageTimer > 0) {
                        this.LifeStageTimer--;
                        if (this.LifeStageTimer <= 0) {
                            switch (this.LifeStage) {
                                case 0:
                                    this.LifeStage = 1;
                                    this.LifeStageTimer = this.LifeStageDuration;
                                    this.AttachAnim("Fire", "01", 4, IsoFireManager.FireAnimDelay, -16, -72, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                                    this.square.Burn();
                                    if (this.LightSource != null) {
                                        this.setLightRadius(5);
                                    }
                                    break;
                                case 1:
                                    this.LifeStage = 2;
                                    this.LifeStageTimer = this.LifeStageDuration;
                                    this.RemoveAttachedAnims();
                                    this.AttachAnim("Smoke", "02", 4, IsoFireManager.SmokeAnimDelay, -9, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                                    this.AttachAnim("Fire", "02", 4, IsoFireManager.FireAnimDelay, -9, -52, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                                    this.square.Burn();
                                    if (this.LightSource != null) {
                                        this.setLightRadius(8);
                                    }
                                    break;
                                case 2:
                                    this.LifeStage = 3;
                                    this.LifeStageTimer = this.LifeStageDuration / 3;
                                    this.RemoveAttachedAnims();
                                    this.AttachAnim("Smoke", "03", 4, IsoFireManager.SmokeAnimDelay, 0, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                                    this.AttachAnim("Fire", "03", 4, IsoFireManager.FireAnimDelay, -16, -72, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                                    if (this.LightSource != null) {
                                        this.setLightRadius(12);
                                    }
                                    break;
                                case 3:
                                    this.LifeStage = 4;
                                    this.LifeStageTimer = this.LifeStageDuration / 3;
                                    this.RemoveAttachedAnims();
                                    this.AttachAnim("Smoke", "02", 4, IsoFireManager.SmokeAnimDelay, 0, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                                    this.AttachAnim("Fire", "02", 4, IsoFireManager.FireAnimDelay, -16, -85, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                                    if (this.LightSource != null) {
                                        this.setLightRadius(8);
                                    }
                                    break;
                                case 4:
                                    this.LifeStage = 5;
                                    this.LifeStageTimer = this.LifeStageDuration / 3;
                                    this.RemoveAttachedAnims();
                                    this.AttachAnim("Smoke", "01", 4, IsoFireManager.SmokeAnimDelay, -9, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                                    if (this.LightSource != null) {
                                        this.setLightRadius(1);
                                    }
                            }
                        }
                    }

                    if (this.Life > 0) {
                        this.Life--;
                        if (this.LifeStage > 0 && this.SpreadTimer > 0) {
                            this.SpreadTimer--;
                            if (this.SpreadTimer <= 0) {
                                if (this.LifeStage != 5) {
                                    this.Spread();
                                }

                                this.SpreadTimer = this.SpreadDelay;
                            }
                        }

                        if (this.Energy > 0) {
                            continue;
                        }

                        this.extinctFire();
                        break;
                    }

                    this.extinctFire();
                    break;
                }
            }
        }
    }

    @Override
    public void render(float x, float y, float z, ColorInfo col, boolean bDoChild, boolean bWallLightingPass, Shader shader) {
        x += 0.5F;
        y += 0.5F;
        this.sx = 0.0F;
        this.offsetX = 0.0F;
        this.offsetY = 0.0F;
        float _float = (float)Core.TileScale;

        for (int _int = 0; _int < this.AttachedAnimSprite.size(); _int++) {
            IsoSprite isoSprite = ((IsoSpriteInstance)this.AttachedAnimSprite.get(_int)).parentSprite;
            if (isoSprite != null && isoSprite.CurrentAnim != null && isoSprite.def != null) {
                Texture texture = ((IsoDirectionFrame)isoSprite.CurrentAnim.Frames.get((int)isoSprite.def.Frame)).directions[this.dir.index()];
                if (texture != null) {
                    isoSprite.soffX = (short)((int)(-((float)(texture.getWidthOrig() / 2) * _float)));
                    isoSprite.soffY = (short)((int)(-((float)texture.getHeightOrig() * _float)));
                    ((IsoSpriteInstance)this.AttachedAnimSprite.get(_int)).setScale(_float, _float);
                }
            }
        }

        super.render(x, y, z, col, bDoChild, bWallLightingPass, shader);
        if (Core.bDebug) {
        }
    }

    public void extinctFire() {
        this.square.getProperties().UnSet(IsoFlagType.burning);
        this.square.getProperties().UnSet(IsoFlagType.smoke);
        this.RemoveAttachedAnims();
        this.square.getObjects().remove(this);
        this.square.RemoveTileObject(this);
        this.setLife(0);
        this.removeFromWorld();
    }

    int getSquaresEnergyRequirement(IsoGridSquare isoGridSquare) {
        int _int = 30;
        if (isoGridSquare.getProperties().Is(IsoFlagType.vegitation)) {
            _int = -15;
        }

        if (!isoGridSquare.getProperties().Is(IsoFlagType.exterior)) {
            _int = 40;
        }

        if (isoGridSquare.getFloor() != null && isoGridSquare.getFloor().getSprite() != null) {
            _int = isoGridSquare.getFloor().getSprite().firerequirement;
        }

        return TutorialManager.instance.Active ? _int / 4 : _int;
    }

    public void setSpreadDelay(int _SpreadDelay) {
        this.SpreadDelay = _SpreadDelay;
    }

    public int getSpreadDelay() {
        return this.SpreadDelay;
    }

    public void setLife(int _Life) {
        this.Life = _Life;
    }

    public int getLife() {
        return this.Life;
    }

    public int getEnergy() {
        return this.Energy;
    }

    public boolean isPermanent() {
        return this.perm;
    }

    public void setLifeStage(int lifeStage) {
        if (this.perm) {
            this.RemoveAttachedAnims();
            switch (lifeStage) {
                case 0:
                    this.AttachAnim("Fire", "01", 4, IsoFireManager.FireAnimDelay, -16, -72, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                    break;
                case 1:
                    this.AttachAnim("Smoke", "02", 4, IsoFireManager.SmokeAnimDelay, -9, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                    this.AttachAnim("Fire", "02", 4, IsoFireManager.FireAnimDelay, -9, -52, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                    break;
                case 2:
                    this.AttachAnim("Smoke", "03", 4, IsoFireManager.SmokeAnimDelay, 0, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                    this.AttachAnim("Fire", "03", 4, IsoFireManager.FireAnimDelay, -16, -72, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                    break;
                case 3:
                    this.AttachAnim("Smoke", "02", 4, IsoFireManager.SmokeAnimDelay, 0, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
                    this.AttachAnim("Fire", "02", 4, IsoFireManager.FireAnimDelay, -16, -85, true, 0, false, 0.7F, IsoFireManager.FireTintMod);
                    break;
                case 4:
                    this.AttachAnim("Smoke", "01", 4, IsoFireManager.SmokeAnimDelay, -9, 12, true, 0, false, 0.7F, IsoFireManager.SmokeTintMod);
            }
        }
    }

    public void setLightRadius(int radius) {
        this.LightRadius = radius;
        if (this.LightSource != null && radius != this.LightSource.getRadius()) {
            this.getCell().removeLamppost(this.LightSource);
            this.LightSource = new IsoLightSource(this.square.getX(), this.square.getY(), this.square.getZ(), 0.61F, 0.165F, 0.0F, this.LightRadius);
            this.getCell().getLamppostPositions().add(this.LightSource);
            IsoGridSquare.RecalcLightTime = -1;
            zombie.GameTime.instance.lightSourceUpdate = 100.0F;
        }
    }

    public int getLightRadius() {
        return this.LightRadius;
    }

    @Override
    public void addToWorld() {
        if (this.perm) {
            this.getCell().addToStaticUpdaterObjectList(this);
        } else {
            IsoFireManager.Add(this);
        }
    }

    @Override
    public void removeFromWorld() {
        if (!this.perm) {
            IsoFireManager.Remove(this);
        }

        IsoFireManager.stopSound(this);
        if (this.LightSource != null) {
            this.getCell().removeLamppost(this.LightSource);
            this.LightSource = null;
        }

        if (this.heatSource != null) {
            this.getCell().removeHeatSource(this.heatSource);
            this.heatSource = null;
        }

        super.removeFromWorld();
    }

    @Override
    public void saveChange(String string, KahluaTable kahluaTable, ByteBuffer byteBuffer) {
        super.saveChange(string, kahluaTable, byteBuffer);
        if ("Energy".equals(string)) {
            byteBuffer.putInt(this.Energy);
        } else if ("lightRadius".equals(string)) {
            byteBuffer.putInt(this.getLightRadius());
        }
    }

    @Override
    public void loadChange(String change, ByteBuffer bb) {
        super.loadChange(change, bb);
        if ("Energy".equals(change)) {
            this.Energy = bb.getInt();
        }

        if ("lightRadius".equals(change)) {
            int _int = bb.getInt();
            this.setLightRadius(_int);
        }
    }

    public boolean isCampfire() {
        if (this.getSquare() == null) {
            return false;
        } else {
            IsoObject[] isoObject0 = this.getSquare().getObjects().getElements();
            int int0 = 1;

            for (int int1 = this.getSquare().getObjects().size(); int0 < int1; int0++) {
                IsoObject isoObject1 = isoObject0[int0];
                if (!(isoObject1 instanceof IsoWorldInventoryObject) && "Campfire".equalsIgnoreCase(isoObject1.getName())) {
                    return true;
                }
            }

            return false;
        }
    }
}
